package org.bonorsoft.modules.mobile.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.bonorsoft.modules.mobile.entity.MobileUser;
import redis.clients.jedis.params.Params;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

public interface MobileUserMapper extends BaseMapper<MobileUser> {
    /**
     * 通过用户账号查询用户信息
     * @param username
     * @return
     */
    public MobileUser getUserByName(@Param("username") String username);

    @Update("update sys_user SET dept_id = #{deptId} where id = #{userId}")
    void updateUserDepart(String username, Long deptId);

    List<String> getAllMenuUser(Long menuId);

    @Select("select u.id from sys_user u left join sys_user_role ur on u.id = ur.user_id where ur.id = #{roleId}")
    List<String> getAllRoleUser(Integer roleId);

    IPage<MobileUser> selectUser(Page<MobileUser> page,
                                 @Param("mobileUser") MobileUser mobileUser,
                                 @Param("params") Params params,
                                 @Param("dataSql") String sql);

    IPage<MobileUser> pageByConditions(Page<MobileUser> page,
                                    @Param("mobileUser") MobileUser mobileUser,
                                    @Param("roleId") String roleId,
                                    @Param("dataSql") String sql);

    boolean removeByIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
}
